﻿using System.Text;
using System.Globalization;
using Utilities;
using WebSite_HaiSheng.Utilities;

namespace System.Web.Mvc
{

    public static class HtmlExtensions
    {
        public static HtmlString SimplePager(this HtmlHelper helper,int currentPage, int pageCount, string urlTemplate,string pagerClass)
        {
            if (currentPage < 0) currentPage = 1;
            if (pageCount < 0) pageCount = 0;
            var pager = new PagerBuilder(urlTemplate);
            pager.PagerClass = pagerClass;
            if (currentPage > 1)
            {
                pager.AddPage("&lt;&lt;", 1);
                pager.AddPage("&lt;", 1);
            }

            var start = Math.Max(currentPage - 2, 1);
            var end = Math.Min(pageCount, currentPage + 2);

            for (var i = start; i <= end; i++)
            {
                if (i == currentPage)
                    pager.AddPage(i.ToString(), i, "current");
                else
                    pager.AddPage(i.ToString(), i);
            }

            if (currentPage < pageCount)
            {
                pager.AddPage("&gt;", currentPage + 1);
                pager.AddPage("&gt;&gt;", pageCount);
            }
            return GetHtmlString(pager.ToString());

        }
        public static HtmlString GetHtmlString(string s)
        {
            return new HtmlString(s);
        }
    }
}